/**
 * Copyright(C) 2008 Matthias Braunhofer
 * All rights reserved
 *
 * Created on: 26.07.2008
*/

package it.cums.core.model;

import java.beans.PropertyChangeListener;
import java.util.ArrayList;

public class Orders {
	private Customer customer;
	private ArrayList<Order> orders = new ArrayList<Order>();
	private ArrayList<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
	
	public ArrayList<Order> getOrders() {
		return orders;
	}
	
	public void addOrder(Order order) {
		orders.add(order);
		order.setPropertyChangeListeners(listeners);
		notifyListeners();
	}
	
	public void removeOrder(Order order) {
		orders.remove(order);
		notifyListeners();
	}
	
	public Orders(Customer customer) {
		this.customer = customer;
		customer.setOrders(this);
	}
	
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	
	public Customer getCustomer() {
		return customer;
	}
	
	private void notifyListeners() {
		for (PropertyChangeListener listener : listeners) {
			listener.propertyChange(null);
		}
	}
	
	public void addChangeListener(PropertyChangeListener listener) {
		listeners.add(listener);
	}
}
